// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PEX_OBSERVATION_PEX_P08 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 PEO",21)]
  	    [HL7Field(HL7Version.v23, 21, HL7Repeat.False, HL7Required.True,"PEO")]
	    public PEO PEO {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("22 PEX_CAUSE",22)]
  	    [HL7Field(HL7Version.v23, 22, HL7Repeat.True, HL7Required.True,"PEX_CAUSE_PEX_P08")]
	    public PEX_CAUSE_PEX_P08[] PEX_CAUSE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("42 PRB",42)]
  	    [HL7Field(HL7Version.v23, 42, HL7Repeat.True, HL7Required.False,"PRB")]
  	    [HL7Field(HL7Version.v23, 75, HL7Repeat.True, HL7Required.False,"PRB")]
	    public PRB[] PRB {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("47 OBX",47)]
  	    [HL7Field(HL7Version.v23, 47, HL7Repeat.True, HL7Required.False,"OBX")]
  	    [HL7Field(HL7Version.v23, 80, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("52 NTE",52)]
  	    [HL7Field(HL7Version.v23, 52, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("55 ASSOCIATED_PERSON",55)]
  	    [HL7Field(HL7Version.v23, 55, HL7Repeat.False, HL7Required.False,"ASSOCIATED_PERSON_PEX_P08")]
	    public ASSOCIATED_PERSON_PEX_P08 ASSOCIATED_PERSON {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PEO = PopSegmentParseAndCheckRequired<PEO>(availableData, options, "PEO");
			PEX_CAUSE = ProcessGroupArray<PEX_CAUSE_PEX_P08>(availableData, options, "PEX_CAUSE");
			PRB = PopSegmentParseAndCheckRequiredArray<PRB>(availableData, options, "PRB");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			ASSOCIATED_PERSON = ProcessGroup<ASSOCIATED_PERSON_PEX_P08>(availableData, options, "ASSOCIATED_PERSON");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPEO = availableData.StartsWith("PEO", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PEO", options.Version) || isPEO) {
				return isPEO;
			}
			PEX_CAUSE_PEX_P08 testPEX_CAUSE_PEX_P08 = new PEX_CAUSE_PEX_P08();
			bool grpCCPEX_CAUSE_PEX_P08 = (testPEX_CAUSE_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("PEX_CAUSE", options.Version) || grpCCPEX_CAUSE_PEX_P08) {
				return grpCCPEX_CAUSE_PEX_P08;
			}
			bool isPRB = availableData.StartsWith("PRB", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRB", options.Version) || isPRB) {
				return isPRB;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			ASSOCIATED_PERSON_PEX_P08 testASSOCIATED_PERSON_PEX_P08 = new ASSOCIATED_PERSON_PEX_P08();
			bool grpCCASSOCIATED_PERSON_PEX_P08 = (testASSOCIATED_PERSON_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("ASSOCIATED_PERSON", options.Version) || grpCCASSOCIATED_PERSON_PEX_P08) {
				return grpCCASSOCIATED_PERSON_PEX_P08;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PEX_OBSERVATION";
			}
        }

        static PEX_OBSERVATION_PEX_P08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PEX_OBSERVATION_PEX_P08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PEO != null) {
			string segmentValue = PEO.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PEX_CAUSE != null && PEX_CAUSE.Length > 0) {
			for (int i = 0; i < PEX_CAUSE.Length; i++) {
				string segmentValue = PEX_CAUSE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PRB != null && PRB.Length > 0) {
			for (int i = 0; i < PRB.Length; i++) {
				string segmentValue = PRB[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (ASSOCIATED_PERSON != null) {
			string segmentValue = ASSOCIATED_PERSON.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

